package cn.mall.order.controller;

import cn.mall.base.utils.AjaxResult;
import cn.mall.order.domain.Order;
import cn.mall.order.dto.ToolDto;
import cn.mall.order.service.IOrderService;
import cn.mall.order.service.IToolService;
import cn.mall.order.utils.Utils;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestController
@RequestMapping("/tool")
public class ToolController {

    @Autowired
    public IToolService iToolService;

    @PostMapping("/deal")
    public AjaxResult ToolUtils(@RequestBody ToolDto toolDto){
        try {
            //校验该接口是否可以解析数据
            String url = toolDto.getUrl().trim();
            if(!url.contains("m.weibo.cn")){
                url = Utils.dealStr(url);
                toolDto.setUrl(url);
                System.out.println(url);
            }
            toolDto.setUrl(url);
            AjaxResult ajaxResult = Utils.ToolUtils(url);

            return ajaxResult;
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("处理失败"+e.getMessage());
        }
    }
}
